import pygame

from vengine.ve_assets import VE_FontRender, VE_Image
from vengine.ve_coord import Area2d, Point2d
from vengine.ve_globals import get_window
from vengine.ve_objects import VE_Observerable


class VE_TextWidget(VE_Observerable):
    """ Base class for a simple text widget """
    def __init__(
        self,
        object_id: str,
        
        center: Point2d,
        
        text: str,
        fontRender: VE_FontRender
    ) -> None:
        super().__init__(object_id)
        
        self.__center: Point2d = center
        self.__text: str = text
        self.__fontRender: VE_FontRender = fontRender
        
        self.update()
        
    def update(self) -> None:
        self.surface = self.__fontRender.render(self.__text)
        self.area = Area2d(self.surface.get_rect(center=self.__center.to_pygame()))
            
    @property
    def text(self) -> str: return self.__text
    
    @text.setter
    def text(self, text: str) -> None:
        self.__text = text
        self.update()

    def display(self) -> None:
        get_window().blit(
            self.surface,
            self.area.to_pygame()
        )
        
    def tick(self) -> None: ...

class VE_ImageWidget(VE_Observerable):
    """ Base class for a simple image widget """
    def __init__(
        self,
        object_id: str,
        
        center: Point2d,
        
        image: VE_Image
    ) -> None:
        super().__init__(object_id)
        
        self.__center: Point2d = center
        self.__image: VE_Image = image
        self.surface: pygame.Surface = self.__image.image
        self.area = Area2d(self.surface.get_rect(center=self.__center.to_pygame()))
        
    def display(self) -> None:
        get_window().blit(
            self.surface,
            self.area.to_pygame()
        )
        
    def tick(self) -> None: ...